import { request } from "@/plugins/request";

// 获取公共文章列表
export const getArticles = (params) => {
    return request({
        method: "GET",
        url: "/api/articles",
        params,
    });
};

// 获取关注用户文章列表
export const getFeedArticles = (params) => {
    return request({
        method: "GET",
        url: "/api/articles/feed",
        params,
    });
};

// 添加点赞
export const addFavorite = (slug) => {
    return request({
        method: "POST",
        url: `/api/articles/${slug}/favorite`,
    });
};

// 删除点赞
export const deleteFavorite = (slug) => {
    return request({
        method: "DELETE",
        url: `/api/articles/${slug}/favorite`,
    });
};

// 获取公共文章详情
export const getArticle = (slug) => {
    return request({
        method: "GET",
        url: `/api/articles/${slug}`,
    });
};

// 获取文章评论
export const getComments = (slug) => {
    return request({
        method: "GET",
        url: `/api/articles/${slug}/comments`,
    });
};

// 增加评论
export const addComment = (slug, comment) => {
    return request({
        method: "POST",
        url: `/api/articles/${slug}/comments`,
        data: comment,
    });
};

// 删除评论
export const deleteComment = (slug, id) => {
    return request({
        method: "DELETE",
        url: `/api/articles/${slug}/comments/${id}`,
    });
};

// 增加文章
export const addArticle = (params) => {
    return request({
        method: "POST",
        url: `/api/articles`,
        data: params,
    });
};

// 更新文章
export const updateArticle = (slug, data) => {
    return request({
        method: "PUT",
        url: `/api/articles/${slug}`,
        data,
    });
};

// 删除文章
export const deleteArticle = (slug) => {
    return request({
        method: "DELETE",
        url: `/api/articles/${slug}`,
    });
};
